home *** CD-ROM | disk | FTP | other *** search
-
-
- #include "GraphicsModule_Types.h"
- #include "Sounds.h"
- #include <utils.h>
- #include <math.h>
-
-
- // these are the functs that need defined ...
- OSErr DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
- OSErr DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params);
- // these must be defined also
- OSErr DoSelected(RgnHandle blankRgn, short message, GMParamBlockPtr params);
- OSErr DoAboutBox(RgnHandle blankRgn, short message, GMParamBlockPtr params);
-
-
- int errno;
- short gTheScreen;
-
- double gTop, gLeft, gEdge;
- double gIncrement, gScale, gX0, gY0;
-
- short gDeltaX, gDeltaY;
- //long temp[10];
-
-
- #define METHOD (params->controlValues[0])
- #define H_VALUE ( (params->controlValues[1] / 1000.00) > 0 ? \
- (params->controlValues[1] / 1000.00) : 0.001)
-
- #define ZOOM (params->controlValues[2] * 2)
- short gAmount;
- double gHvalue;
- short gZoom;
- short gMethod;
-
- RGBColor gColor1, gColor2;
-
- #define H 0.050
-
-
- //////////////////////////////////////////////////////////////////////////////////////
- // this is the first funct called by AD ... we need to allocate and initialize here
- OSErr
- DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params) {
-
- gDeltaX = gDeltaY = 1;
-
- PickBrightRGB( &gColor1 );
- PickBrightRGB( &gColor2 );
-
- // last things to do
- gMethod = METHOD; // how to do color changes
- gAmount = 55; // was: AMOUNT;
- gZoom = ZOOM;
- gHvalue = H_VALUE;
- gTheScreen = 0; // which monitor to run on
-
- return noErr;
- }
-
- //////////////////////////////////////////////////////////////////////////////////////
- // the screen saver has been awakened! time to ditch the storage and wave goodbye
- OSErr
- DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params) {
-
- return noErr;
- }
-
-
-
- //////////////////////////////////////////////////////////////////////////////////////
- // make the screen go black
- OSErr
- DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params) {
-
- // darken the screen ...
- FillRgn(blankRgn, params->qdGlobalsCopy->qdBlack);
- return noErr;
-
- }
-
- //////////////////////////////////////////////////////////////////////////////////////
- // this is the workhorse routine. It does the continual screen work to make
- // this screen saver what it is.
- OSErr
- DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- short j, k, n;
- double x, y, xx, yy;
- void plot( double x, double y);
- short width, height, windowEdge;
- RGBColor rgbTheColor;
-
-
- // definitely needed :) ... since the PickxxxRGB() colors are useless
- // when we !HasColorQD()
- ForeColor( whiteColor);
- BackColor( blackColor);
-
- // if we're in DEMO mode ... folks like to poke the controls ...
- // so we *have* to respond to that desire to muck about with things
- //
- // has the color-change-menu changed ??
- // or
- // has the AMOUNT (step) slider changed ?
- if ((METHOD != gMethod) ||
- (H_VALUE != gHvalue) ||
- (ZOOM != gZoom) ) {
-
- // reset values and clear the screen
- gDeltaX = gDeltaY = 1;
- EraseRect( &(params->monitors->monitorList[gTheScreen].bounds) );
- // set sliders
- gMethod = METHOD;
- gHvalue = H_VALUE;
- gZoom = ZOOM;
- // choose new colors
- PickBrightRGB( &gColor1 );
- PickBrightRGB( &gColor2 );
- }
- gEdge = gZoom; // how many units whide?
- gLeft = gTop = -( gZoom/2); // left,top point is calc'd to make this centered
-
- width = params->monitors->monitorList[ gTheScreen ].bounds.right -
- params->monitors->monitorList[ gTheScreen ].bounds.left;
-
- height = params->monitors->monitorList[ gTheScreen ].bounds.bottom -
- params->monitors->monitorList[ gTheScreen ].bounds.top;
-
- // pick the smaller side ...
- if (width > height) windowEdge = height;
- else windowEdge = width;
-
- gIncrement = gEdge / gAmount;
- gScale = windowEdge / gEdge;
-
- gX0 = (width / 2) - ((gLeft + (gEdge / 2)) * gScale);
- gY0 = (height / 2) - ((gTop + (gEdge / 2)) * gScale);
-
-
- // color changes ?
- if (HasColorQD() ) {
- // COLOR method #1 /////////////////////////////////////////////
- if (gMethod == 1) // outermost loop is gDeltaX
- SetColorDiff( &rgbTheColor, &gColor1, &gColor2,
- (double)gDeltaX / (double)gAmount );
-
- // COLOR method #2 /////////////////////////////////////////////
- if (gMethod == 2) // inner loop is gDeltaY
- SetColorDiff( &rgbTheColor, &gColor1, &gColor2,
- (double)gDeltaY / (double)gAmount );
- RGBForeColor( &rgbTheColor);
- }
-
-
-
- // everytime we enter this DoDrawFrame() now, we're doing it
- // at each gDeltaY (inner loop)
-
- // inner loop cycles from 1 to AMOUNT
- if (gDeltaY++ > gAmount) { // we're at the end of this loop?
- gDeltaX++; // increment the outside loop
- gDeltaY = 1; // we start back to 1
- }
-
- // outer loop cycles from 1 to AMOUNT
- if (gDeltaX > gAmount) { // are we at the end of this loop?
- // amended: we are done, for this one screen
- // so, time to move to the next screen
- if (++gTheScreen >= params->monitors->monitorCount)
- gTheScreen = 0;
-
- gDeltaX = gDeltaY = 1;
- EraseRect( &(params->monitors->monitorList[gTheScreen].bounds) );
- gMethod = METHOD; // just to be safe
- PickBrightRGB( &gColor1 );
- PickBrightRGB( &gColor2 );
- return noErr; // return out of here
- }
-
- // we must have some drawing to do
- x = gLeft + (gIncrement * gDeltaX);
- y = gTop + (gIncrement * gDeltaY);
-
-
-
- // this is the main drawing loop //////////////////////////////////////////////////
- for ( n = 1; n <= gAmount; ++n ) {
- double theX, theY;
-
- // COLOR method #3 /////////////////////////////////////////////
- if (HasColorQD() && gMethod == 3) { // innermost loop
- SetColorDiff( &rgbTheColor,
- &gColor1, &gColor2,
- ( (double)n / (double)gAmount) );
- RGBForeColor( &rgbTheColor);
- }
- #if 0
- xx = x - H * sin(y + tan(3 * y));
- yy = y - H * sin(x + tan(3 * x));
- #else
- xx = x - H_VALUE * sin(y + tan(3 * y));
- yy = y - H_VALUE * sin(x + tan(3 * x));
- #endif
- x = xx;
- y = yy;
-
- // we could be nice and check to ensure the plotted point is onscreen
- // (should we?) - I'll wait to hear from the multi-monitor folks (overlapped drawing?)
- // nope ... let us not wait ... check to be sure
- theX = params->monitors->monitorList[ gTheScreen ].bounds.left +
- (gScale * x + gX0);
- theY = params->monitors->monitorList[ gTheScreen ].bounds.top +
- (gScale * y + gY0);
- #if 1
- if (theX >= params->monitors->monitorList[gTheScreen].bounds.left &&
- theX <= params->monitors->monitorList[gTheScreen].bounds.right &&
- theY >= params->monitors->monitorList[gTheScreen].bounds.top &&
- theY <= params->monitors->monitorList[gTheScreen].bounds.bottom )
- plot( theX, theY);
- #else
- plot (
- params->monitors->monitorList[ gTheScreen ].bounds.left +
- (gScale * x + gX0),
- params->monitors->monitorList[ gTheScreen ].bounds.top +
- (gScale * y + gY0) );
- #endif
-
- } // for n
-
-
- return noErr;
- }
-
- //////////////////////////////////////////////////////////////////////////////////////
- // this is called when they click on something in the control panel
- OSErr
- DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params) {
- // button got pushed??
- return noErr;
- }
-
-
-
- OSErr DoSelected(RgnHandle blankRgn, short message, GMParamBlockPtr params) {
- return noErr;
- }
-
-
-
- OSErr DoAboutBox(RgnHandle blankRgn, short message, GMParamBlockPtr params) {
- return noErr;
- }
-
-